#!/usr/bin/env python

import unittest

from amlnextbus.route import Route

class TestRoute(unittest.TestCase):
    def setUp(self):
        self.route = Route()

    def testParseRoute(self):
        testStr1 = '      parent.addOption(routeSelector, "F-Market & Wharves", "F", false, true);'
        (name, symbol, restOfStr) = self.route.parseRoute(testStr1)

        self.assertEquals(name, "F-Market & Wharves")
        self.assertEquals(symbol, "F")

        testStr2 = """
      parent.addOption(routeSelector, "39-Coit", "39", false, false);

      parent.addOption(routeSelector, "41-Union", "41", false, false);

      parent.addOption(routeSelector, "43-Masonic", "43", false, false);

      parent.addOption(routeSelector, "44-O'Shaughnessy", "44", false, false);

      parent.addOption(routeSelector, "45-Union/Stockton", "45", false, false);
"""
        expectedNameArr = ["39-Coit", "41-Union", "43-Masonic", "44-O'Shaughnessy", "45-Union/Stockton"]
        expectedSymbolArr = ["39", "41", "43","44", "45"]

        (name, symbol, restOfHtmlStr) = self.route.parseRoute(testStr2)
        i = 0
        while (restOfHtmlStr != None):
            self.assertEquals(name, expectedNameArr[i])
            self.assertEquals(symbol, expectedSymbolArr[i])
        
            i += 1
            (name, symbol, restOfHtmlStr) = self.route.parseRoute(restOfHtmlStr)

    def testGetName(self):
        self.assertEquals(self.route.getName("2"), "2-Clement")
        self.assertEquals(self.route.getName("8AX"), "8AX-Bayshore A Exp")
        self.assertEquals(self.route.getName("9"), "9-San Bruno")

    def testGetSymbol(self):
        self.assertEquals(self.route.getSymbol("K-Owl"), "K OWL")
        self.assertEquals(self.route.getSymbol("71L-Haight-Noriega Limited"), "71L")
        self.assertEquals(self.route.getSymbol("31BX-Balboa B Express"), "31BX")


if __name__ == '__main__':
    unittest.main()


